package com.zoo.boot.service.impl;

import cn.hutool.core.util.StrUtil;
import com.zoo.boot.mapper.LDepartmentsMapper;
import com.zoo.boot.model.LDepartments;
import com.zoo.boot.model.LDepartmentsExample;
import com.zoo.boot.service.DepartmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 部门管理 Service 实现
 *
 * @Author: WangB
 * @Date: 2021/7/2
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Resource
    private LDepartmentsMapper departmentsMapper;


    /**
     * 获取部门列表
     *
     * @param dept
     * @return
     */
    @Override
    public List<LDepartments> list(LDepartments dept) {
        LDepartmentsExample lDepartmentsExample = new LDepartmentsExample();
        if (StrUtil.isNotEmpty(dept.getName())) {
            lDepartmentsExample.createCriteria().andNameLike("%" + dept.getName() + "%");
        }
        List<LDepartments> lDepartments = departmentsMapper.selectByExample(lDepartmentsExample);
        return lDepartments;
    }

    @Override
    public List<LDepartments> getDeptList() {
        return null;
    }


    /**
     * 添加部门信息
     *
     * @param dept
     * @return
     */
    @Override
    public boolean add(LDepartments dept) {
        return departmentsMapper.insert(dept) > 0 ? true : false;
    }

    /**
     * 批量删除部门信息
     *
     * @param ids
     * @return
     */
    @Override
    public boolean batchDelete(List<String> ids) {
        return departmentsMapper.deleteBatchByIds(ids) > 0 ? true : false;
    }

    /**
     * 根据部门号获取部门信息
     *
     * @param deptCode
     * @return
     */
    @Override
    public LDepartments getDeptByCode(String deptCode) {

        return departmentsMapper.selectByPrimaryKey(deptCode);
    }

    /**
     * 根据部门号修改部门名称
     *
     * @param department
     * @return
     */
    @Override
    public boolean updateDeptByCode(LDepartments department) {
        return departmentsMapper.updateByPrimaryKey(department) > 0 ? true : false;
    }

    /**
     * 根据部门编号删除部门信息
     *
     * @param deptCode
     * @return
     */
    @Override
    public boolean deleteDeptById(String deptCode) {
        return departmentsMapper.deleteByPrimaryKey(deptCode) > 0 ? true : false;
    }
}
